package com.xiao.xin.core.handler;

import com.xiao.xin.core.dto.Result;
import com.xiao.xin.core.exception.Text2ImageExecption;
import com.xiao.xin.core.exception.UserFundException;
import com.xiao.xin.core.exception.UserLoginException;
import com.xiao.xin.core.service.UserFundRecordService;
import com.xiao.xin.core.service.UserFundService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/***
 * 全局异常处理器
 */
@RequiredArgsConstructor
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    private final UserFundRecordService userFundRecordService;


    /***
     * 捕获登录异常
     * @param userLoginException
     * @return
     */
    @ExceptionHandler(UserLoginException.class)
    public Result login(UserLoginException userLoginException) {
        log.info("捕捉登录异常信息:{}", userLoginException.getMessage());
        return Result.error(userLoginException.getMessage());
    }

    /***
     * 捕捉积分异常
     * @param userFundException
     * @return
     */
    @ExceptionHandler(UserFundException.class)
    public Result fund(UserFundException userFundException) {
        log.info("捕捉积分:{}", userFundException.getMessage());
        return Result.error(userFundException.getMessage());
    }

    /***
     * 捕捉文生图异常
     * @param text2ImageExecption
     * @return
     */
    @ExceptionHandler(Text2ImageExecption.class)
    public Result text2image(Text2ImageExecption text2ImageExecption) {
        log.info("捕捉积分:{}", text2ImageExecption.getMessage());
        return Result.error(text2ImageExecption.getMessage());
    }
}
